#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations

from autoapi.db.redis import RedisDB
from autoapi.db.memory_cache import MemoryCache
from autoapi.common.log import log


try:
    redis_instance = RedisDB()
    redis_instance.init()
    log.info("✅ 使用 Redis 缓存引擎")
    cache_client = redis_instance
except Exception as e:
    log.warning(f"❌️ Redis 不可用，使用内存缓存 MemoryCache 替代: {e}")
    cache_client = MemoryCache()
    cache_client.init()


def is_redis_available() -> bool:
    """
    判断当前是否使用 Redis 缓存引擎
    """
    return isinstance(cache_client, RedisDB)
